#!/bin/bash
#To fix the initrd to handle the USB CD timeout issue, do the following after expanding the ubuntu iso:

# Expand the original initrd for the install image
sudo rm -rf initrd
sudo mkdir initrd

# sigh -- for some bizzare reason, the bnx2.ko driver does not actually make 
# it on to the initrd -- it is in a .udeb, so the installer will see it after
# the install image is mounted.  Too bad if you wanted to mount the install
# image over nfs on a broadcom nic, though.  Work around this by extracting
# all the nic drivers to the initrd.
sudo mkdir nicdrivers
cd nicdrivers
for udeb in ../../cd-image/pool/main/l/linux/nic-*-generic-*.udeb; do
    sudo ar x "$udeb"
    sudo tar xzf data.tar.gz
    sudo rm debian-binary *.tar.gz
done

cd ../initrd
gzip -dc ../../cd-image/install/initrd.gz | sudo cpio -id

# Copy in fixed cdrom detect script with loop for cd rom timeouts
sudo cp ../cdrom-detect.postinst var/lib/dpkg/info/
# Copy in all the nic drivers we should have had to begin with
sudo cp -a ../nicdrivers/lib .
sudo rm -rf ../nicdrivers

# Build new initrd.gz
find . | sudo cpio --create --format='newc' | sudo gzip -9 > ../new-initrd.gz

cd ..
sudo rm -rf initrd
